<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: zuti666
  Date: 2020/6/23
  Time: 10:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>backend</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/bootstarp/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/css/index.css" />
    <script src="${pageContext.request.contextPath}/statics/js/jquery.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/statics/bootstarp/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/statics/js/userSetting.js" type="text/javascript" charset="utf-8"></script>

    <!-- 添加bootstrap分页js -->
    <script type="text/javascript" src="${pageContext.request.contextPath }/statics/js/bootstrap-paginator.js"></script></head>

<script type="text/javascript">
    $(function()
    {
        $("#staffName").val("${staffParameter.staffName }");
        $("#loginName").val("${staffParameter.loginName }");
        $("#phone").val("${staffParameter.phone }");
        $("#email").val("${staffParameter.email }");
        $("#deptId").find("option[value='${deptId }']").attr("selected", true);
        $("#role").find("option[value='${staffParameter.role }']").attr("selected", true);
        $("#isValid").find("option[value='${staffParameter.isValid }']").attr("selected", true);



        // 清空
        $("#res").click(function()
        {
            $("#staffName").val("");
            $("#loginName").val("");
            $("#phone").val("");
            $("#email").val("");
            $("#deptId")[0].options.selectedIndex = 0;
            $("#role")[0].options.selectedIndex = 0;
            $("#isValid")[0].options.selectedIndex = 0;
            alert(11);
        });


        // 添加管理员
        $("#addStaff").click(function()
        {
            $.ajax(
                {
                    type:"post",
                    url:"${pageContext.request.contextPath}/staff/addStaff",
                    data:{
                        "staffName":$("#addStaffName").val(),
                        "loginName":$("#addLoginName").val(),
                        "password":$("#addPassword").val(),
                        "phone":$("#addPhone").val(),
                        "email":$("#addEmail").val(),
                        "deptId":$("#addDept")[0].options[$("#addDept")[0].selectedIndex].value,
                        "role":$("#addRole")[0].value
                    },
                    dataType:"json",
                    success:function(result)
                    {
                        if (result.responseCode == 1)
                        {
                            location.href="${pageContext.request.contextPath}/staff/searchByParamList?pageIndex=${pageSupport.currentPageNo}";
                        }else
                        {
                            $("#errorMsg").tooltip(
                                {
                                    title:"error",
                                    placement:"center",
                                    template:"<div class='tooltip errorMsg'>" + result.message + "</div>",
                                    tigger:"manual"
                                }).tooltip("show");
                        }
                    }
                });
        });

// 做修改管理员操作时  查询出修改页面的管理员信息"#toModify"
        $("input[name='toModify']" ).click(function()
        {
            $.ajax(
                {
                    type : "post",
                    url  : "${pageContext.request.contextPath}/staff/findById",
                    data : {
                        "staffId" : $(this).attr("data-id"),
                        "isValid" : $(this).attr("data-status")
                    },
                    dataType : "json",
                    success  :  function(result)
                    {
                        if (result.responseCode === 1)
                        {
                            $("#modifyStaffId").val(result.returnObject.staffId);
                            $("#modifyStaffName").val(result.returnObject.staffName);
                            $("#modifyLoginName").val(result.returnObject.loginName);
                            $("#modifyPhone").val(result.returnObject.phone);
                            $("#modifyEmail").val(result.returnObject.email);
                            $("#modifyRole").val(result.returnObject.role);

                            if(result.returnObject.dept != null)
                            {
                                $("#modifyDept").val(result.returnObject.dept.deptId);
                            }else
                            {
                                $("#modifyDept").val("-1");
                            }
                        }else
                        {
                            $("#errorMsg").tooltip(
                                {
                                    title : "error",
                                    placement : "center",
                                    template : "<div class='tooltip errorMsg'>" + result.message + "</div>",
                                    tigger : "manual"
                                }).tooltip("show");
                        }
                    }
                });
        });
        // 修改管理员信息
        $("#modifyStaff").click(function()
        {
            $.ajax(
                {
                    type : "post",
                    url  :  "${pageContext.request.contextPath }/staff/modifyStaff",
                    data :  {
                        "staffId"   :  $("#modifyStaffId").val(),
                        "staffName" :  $("#modifyStaffName").val(),
                        "phone"     :  $("#modifyPhone").val(),
                        "email"     :  $("#modifyEmail").val(),
                        "role"      :  $("#modifyRole").val(),
                        "deptId"    :  $("#modifyDept").val()
                    },
                    dataType : "json",
                    success  :  function(result)
                    {
                        if (result.responseCode === 1)
                        {
                            location.href = "${pageContext.request.contextPath }/staff/searchByParamList?pageIndex=${pageSupport.currentPageNo}";
                        }else
                        {
                            $("#errorMsg").tooltip(
                                {
                                    title     : "error",
                                    placement : "center",
                                    template  : "<div class='tooltip errorMsg'>" + result.message + "</div>",
                                    tigger    : "manual"
                                }).tooltip("show");
                        }
                    }
                });
        });

        // 管理员 启用/禁用
        $("input[name='modifyStatus']").click(function()
        {
            $.ajax(
                {
                    type : "post",
                    url  : "${pageContext.request.contextPath}/staff/modifyStaffStatus",
                    data : {
                        "staffId" : $(this).attr("data-id"),
                        "isValid"  : $(this).attr("data-status")
                    },
                    dataType : "json",
                    success  : function(result)
                    {
                        if (result.responseCode == 1)
                        {
                            location.href = "${pageContext.request.contextPath }/staff/searchByParamList";
                        }else
                        {
                            $("#errorMsg").tooltip(
                                {
                                    title :  "error",
                                    placement : "center",
                                    template  : "<div class='tooltip errorMsg'>"  + result.message +"</div>",
                                    tigger    :  "manual"
                                }).tooltip("show");
                        }
                    }

                });
        });
    });
</script>
</head>

<body>
<!-- 管理员管理 -->
<div class="panel panel-default" id="adminSet">
    <div class="panel-heading">
        <h3 class="panel-title">管理员管理</h3>
    </div>
    <div class="panel-body">
        <div class="showmargersearch">
            <form class="form-inline" id="searchForm" action="${pageContext.request.contextPath }/staff/searchByParamList" method="post">
                <div class="form-group">
                    <label >姓名:</label>
                    <input type="text" class="form-control" id="searchUserName" name="searchUserName" placeholder="请输入姓名" value="${UserName}">
                </div>
                <div class="form-group">
                    <label >帐号:</label>
                    <input type="text" class="form-control" id="searchLoginName" name="searchLoginName" placeholder="请输入帐号" value="${LoginName}">
                </div>
                <div class="form-group">
                    <label >电话:</label>
                    <input type="text" class="form-control" id="searchPhone"  name="searchPhone" placeholder="请输入电话" value="${Phone}">
                </div>
                <div class="form-group">
                    <label >邮箱:</label>
                    <input type="email" class="form-control" id="searchEmail" name="searchEmail" placeholder="请输入邮箱" value="${Email}">
                </div>
                <div class="form-group">
                    <label >部门</label>
                    <c:if test="${deptList != null}">
                    <select class="form-control" name="searchDeptId" id="searchDeptId" >
                        <option value="">--请选择--</option>
                        <c:forEach var="dept" items="${deptList}">
                            <option
                                <c:if test="${dept.deptId == DeptId}">selected="selected"</c:if>
                                value="${dept.deptId}">
                                    ${dept.deptName}
                            </option>
                        </c:forEach>
                    </select>
                    </c:if>
                </div>
                <div class="form-group">
                    <label >角色</label>
                    <select class="form-control" name="searchRole" id="searchRole">
                        <option value="">全部</option>
                        <option value="1">系统管理员</option>
                        <option value="0">普通管理员</option>
                    </select>
                </div>
                <div class="form-group">
                    <label >状态</label>
                    <select class="form-control" name="searchIsValid" id="searchIsValid" >
                        <option value="-1">全部</option>
                        <option <c:if test="${IsValid == 1}">selected="selected"</c:if>value="1">---有效---</option>
                        <option <c:if test="${IsValid == 0}">selected="selected"</c:if>value="0">---无效---</option>
                    </select>
                </div>
                <input type="hidden" name="pageIndex" value="1"/>
                <input type="submit" value="查询" class="btn btn-primary" id="doSearch">
            </form>
        </div>
        <br>
        <br>
        <input type="button" value="添加管理员" class="btn btn-primary" id="doAddManger">
        <!-- 添加管理员 -->
        <div class="modal fade" tabindex="-1" id="myMangerUser">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">添加管理员</h4>
                    </div>
                    <div class="modal-body text-center">
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">用户姓名：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="addStaffName">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">登录帐号：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="addLoginName">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">登录密码：</label>
                            <div class="col-sm-4">
                                <input type="password" class="form-control" id="addPassword">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label class="col-sm-4 control-label">联系电话：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="addPhone">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">联系地址：</label>
                            <div class="col-sm-4">
                                <input type="email" class="form-control" id="addEmail">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">角&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色：</label>
                            <div class=" col-sm-4">
                                <select class="form-control" id="addRole">
                                    <option>请选择</option>
                                    <option>系统管理员</option>
                                    <option>普通管理员</option>
                                </select>
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门：</label>
                            <div class=" col-sm-4">
                                <select class="form-control" id="addDept">
                                    <option value="">--请选择--</option>
                                    <c:forEach var="dept" items="${deptList}">
                                        <option
                                                <c:if test="${dept.deptId == DeptId}">selected="selected"</c:if>
                                                value="${dept.deptId}">
                                                ${dept.deptName}
                                        </option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <br/>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-primary add-Manger" id="addStaff">添加</button>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- 管理员修改 -->
        <div class="modal fade" tabindex="-1" id="myModal-Manger">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">管理员修改</h4>
                    </div>
                    <div class="modal-body text-center">
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">id：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control"   id="modifyStaffId" name="modifyStaffId" readonly="readonly">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">管理员姓名：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyStaffName" name="modifyStaffName">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">登录帐号：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyLoginName"  name="modifyLoginName" readonly="readonly">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">联系电话：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyPhone" naem="modifyPhone">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">联系地址：</label>
                            <div class="col-sm-4">
                                <input type="email" class="form-control" id="modifyAdrees" name="modifyAdrees">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">角&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色：</label>
                            <div class=" col-sm-4">
                                <select class="form-control" id="modifyRole" name="modifyRole">
                                    <option>请选择</option>
                                    <option>系统管理员</option>
                                    <option>普通管理员</option>
                                </select>
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门：</label>
                            <div class=" col-sm-4">
                                <select class="form-control" id="modifyDept" name="modifyDept">
                                    <option value="">--请选择--</option>
                                    <c:forEach var="dept" items="${deptList}">
                                        <option
                                                <c:if test="${dept.deptId == DeptId}">selected="selected"</c:if>
                                                value="${dept.deptId}">
                                                ${dept.deptName}
                                        </option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <br/>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-warning doMargerModal" id="modifyStaff">修改</button>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="show-list" style="position: relative; top: 10px;">


            <table class="table table-bordered table-hover" style='text-align: center;'>
                <thead>
                <tr class="text-danger">
                    <th class="text-center">序号</th>
                    <th class="text-center">姓名</th>
                    <th class="text-center">帐号</th>
                    <th class="text-center">电话</th>
                    <th class="text-center">邮箱</th>
                    <th class="text-center">部门</th>
                    <th class="text-center">状态</th>
                    <th class="text-center">角色</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                <c:forEach items="${StaffList}" var="staff" varStatus="i">
                    <tr>
                        <td>${staff.staffId}</td>
                        <td>${staff.staffName }</td>
                        <td>${staff.loginName }</td>
                        <td>${staff.phone }</td>
                        <td>${staff.email }</td>
                        <td>
                            <c:choose>
                                <c:when test="${empty staff.dept }">--</c:when>
                                <c:otherwise>${staff.dept.deptName }</c:otherwise>
                            </c:choose>
                        </td>

                        <td>
                            <c:if test="${staff.isValid eq 0 }">无效</c:if>
                            <c:if test="${staff.isValid eq 1 }">有效</c:if>
                        </td>

                        <td>
                            <c:if test="${staff.role eq 2001 }">系统管理员</c:if>
                            <c:if test="${staff.role eq 2002 }">普通管理员</c:if>
                        </td>


                        <td class="text-center">

                            <input type="button" class="btn btn-warning btn-sm doMangerModify" id="toModify" name="toModify" value="修改" data-id="${staff.staffId}" data-status="${staff.isValid }">

                            <c:if test="${staff.isValid eq 0 }">
                                <input type="button" class="btn btn-danger btn-sm doMangerDisable" id="modifyStatus" name="modifyStatus"  value="启用" data-id="${staff.staffId}" data-status="${staff.isValid }">
                            </c:if>
                            <c:if test="${staff.isValid eq 1 }">
                                <input type="button" class="btn btn-danger btn-sm doMangerDisable" id="modifyStatus" name="modifyStatus"  value="禁用" data-id="${staff.staffId}" data-status="${staff.isValid }">
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
                <input type="hidden" id="totalPageCount" value="${pageSupport.totalPageCount}"/>
                <c:import url="../rollpage.jsp">
                    <c:param name="totalCount" value="${pageSupport.totalCount}"/>
                    <c:param name="currentPageNo" value="${pageSupport.currentPageNo}"/>
                    <c:param name="totalPageCount" value="${pageSupport.totalPageCount}"/>
                </c:import>

        </div>
    </div>
</div>
</body>

</html>
